
//load data
function loadDom3Data(fn) {

	modctx.itemdata = parseTextToTable(BaseI);
	modctx.itemlookup = createLookup(modctx.itemdata, 'id', 'name');
	
	modctx.armordata = parseTextToTable(BaseA);
	modctx.armorlookup = createLookup(modctx.armordata, 'id', 'name')
	
	modctx.wpndata = parseTextToTable(BaseW);
	modctx.wpnlookup = createLookup(modctx.wpndata, 'id', 'name')
}



function parseTextToTable(str) {
	var t = [];
	
	var lines = str.split("\n");
	var keynames = lines[0].split("\t");

	for (var i=1; i<lines.length; i++) {
		var values = lines[i].split("\t");
		
		if (values[0]=="")
			continue;
		
		var o = new Object();
		for (var j=0; j<keynames.length; j++) {
			var key = keynames[j];
			if (values[j] != "" && values[j] != "\r") {
				if (key == 'id#') key = 'id';
				o[key] = values[j];
			}
		}
		t.push(o);	 
	}	
	return t;
}

function createLookup(t, k1, k2) {
	var o = {};
	for (var i=0; i<t.length; i++) {
		var line = t[i];
		o[line[k1]] = line;
		if (k2) 
			o[line[k2]] = line;
	}
	return o;
}
